package com.qf.fronted.dao.impl;

import com.qf.admin.domain.Pay;
import com.qf.fronted.dao.PayDao;
import com.qf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;

public class PayDaoImpl implements PayDao {

    QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

    @Override
    public void savePayInfo(String orderNo, Integer userId, String payInfo, BigDecimal amount,String tradeNo,String trade_status, Connection connection) {
        String sql = "insert into pay(order_no,user_id,pay_info,total_amount,trade_no,trade_status) values(?,?,?,?,?,?)";
        try {
            queryRunner.update(connection, sql, orderNo, userId, payInfo, amount, tradeNo,trade_status);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    public Object getPay(String out_trade_no) {
        String sql = "select 1 from pay where order_no=?";
        try {
            return queryRunner.query(sql, new ScalarHandler<>(), out_trade_no);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
